package net.fiodor.log.channel {
	import flash.external.ExternalInterface;	
	import flash.utils.getQualifiedClassName;	
	
	import eu.szemraj.logging.LogLevel;
	import eu.szemraj.logging.channel.ILogChannel;		

	/**
	 * @author tswierszcz
	 */
	public class FireBugChannelOld implements ILogChannel {
	
	
	public function log(message:*, logLevel:LogLevel, loggingObject:String) : void{
		
		if(!ExternalInterface.available) return;
		
		var methodName:String;
			
			switch( logLevel  ) {
				
			 case LogLevel.NONE : 
				
					 break;
			 case LogLevel.DEBUG : 
				     methodName = "console.debug";
			    	 break;
			 case LogLevel.INFO : 
					methodName = "console.info";
			 		 break;
			 case LogLevel.WARN : 
					methodName = "console.warn";
			 		break;
			 case LogLevel.ERROR : 
					methodName = "console.error";
			 		break;
			 case LogLevel.FATAL : 
					methodName = "console.fatal";
			 		break;
			 			
			 default : 
			 		 methodName = "console.debug";
				
			}
			
    		ExternalInterface.call( methodName, loggingObject+" "+message) ;
			
	}
	
	public function inspectObject(object:*, objectName:String = "object"):void {
      	
         displayCurrentObject( object );
    }
    
    private function displayCurrentObject( object:*, indent:String = ""  ):void {
      	
         if( object is String || object is Number || object is Boolean ) {
         
            trace( indent + object + "\n" );	
         }
      	else {
      		
            for( var n:* in object ) {
               if( isPrimitiveObject( object[n] ) ) {
	      			
                  trace( indent + n + " : " + object[ n ] + " [ " + getQualifiedClassName( object[n] ) + " ]" );
               }
    	  		else {
      			
                  trace( indent + n + " " + getQualifiedClassName( object[n] ) + " :" );
                  displayCurrentObject( object[ n ], indent + "    " );
               }
            }
         }
      }
      
    private function isPrimitiveObject( object:* ):Boolean {
         
         return ( object is Boolean || object is Number || object is String || object is XML || !object );
         
      }
	
	public function clearOutput() : void{
	}
	
}

}